<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
              <a>
              <cite>合同业务</cite></a>
              <a>
              <cite>合同分类</cite></a>
            <a href="">已转发未确认合同</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="开始日" name="startDate" id="startDate">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="截止日" name="endDate" id="endDate">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="projectName"  placeholder="请输入项目名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="nickName"  placeholder="请输入创建人" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table id="demo" class="layui-table layui-form" lay-filter="demo"></table></div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="show">
    <a title="详情"  lay-event="show_details"  href="javascript:;">详情<i class="layui-icon">&#xe642;</i></a>
    <a title="提醒"  lay-event="remind"  href="javascript:;">提醒<i class="layui-icon">&#xe645;</i></a>
</script>
<script type="text/html" id="msg">
    <span class="layui-btn layui-btn layui-btn-mini">已转发未确认</span>
</script>
<script>
    function isEmpty(val){
        if(val == null || val == undefined || val == ''){
            return null;
        } else {
            return val;
        }
    }
    layui.use(['laydate'], function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#startDate' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#endDate' //指定元素
        });
    });
    layui.use(['table','form'], function(){
        var table = layui.table;
        table.render({
            elem: '#demo'
            ,id:'list'
            ,dateType: "json"
            ,contentType : "application/json"
            ,method: 'post'
            ,where: {state: 2}
            ,url: '/contract/list'
            ,cols: [[ //标题栏
                {field: 'level1SystemId', title: '合同ID'}
                ,{field: 'projectName', title: '项目名称'}
                ,{field: 'username', title: '创建人', sort: true}
                ,{field: 'createDate', title: '合同创建时间', sort: true}
                ,{field: 'deliveryDate', title: '最后交付时间', sort: true}
                ,{field: 'state', title: '转发情况', toolbar: '#msg'}
                ,{fixed: 'right', title:'操作', toolbar: '#show'}
            ]]
            ,skin: 'row' //表格风格
            ,even: true
            ,page: true //是否显示分页
            ,limits: [5,10,20]
            ,limit: 5 //每页默认显示的数量
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0,
                    "count": res.dataSize, //解析数据长度
                    "data": res.data.level1SystemList, //解析数据列表
                    "msg":""
                };
            }
            ,done : function(res, curr, count){
                table_data=res.data;
                layer.closeAll('loading');
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event == 'show_details'){
                //console.log(obj.data.id);
                //xadmin.open('详情','./table-show.html?status=002&tableId='+obj.data.level1SystemId,1200,800);
                var text = obj.data.projectName + " 合同详情"
                xadmin.add_tab(text,'./table-show.html?status=002&tableId='+obj.data.level1SystemId);
                $('#tab_show').show();
                top.location.reload();
            }
            else if(obj.event == 'remind'){
                layer.confirm('是否要提醒?', {icon: 3, title:'警告'}, function(index) {
                    $.ajax({
                        type: 'get',
                        dateType: "json",
                        url: "/contract/remind",
                        data:{level1SystemId: obj.data.level1SystemId},
                        success: function (res) {
                            if (res.msg == 'success') {
                                layer.msg("提醒成功!");
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                setTimeout(
                                    function () {
                                        parent.layer.close(index);//关闭弹出的子页面窗口*!/
                                    }, 1000)
                            } else {
                                layer.msg('提醒失败!');
                            }
                        }
                    });
                });
            }
        });
        var form = layui.form;
        form.on('submit(search)', function(data){
            layer.load();
            table.reload('list',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where:{
                    'state': 2,
                    'createDate' : isEmpty(data.field.startDate),
                    'deliveryDate' : isEmpty(data.field.endDate),
                    'projectName' : isEmpty(data.field.projectName),
                    'username' : isEmpty(data.field.nickName)
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>

</html>
